<!DOCTYPE html>
<html lang="zh_cn">
<head>
          <title>来玩魔王的咚</title>
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta charset="utf-8" />
        <!-- twitter card metadata -->
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="/images/mowang.png">
<meta name="twitter:site" content="">
<meta name="twitter:title" content="Docker 私有Registry">
<meta name="twitter:description" content="<p>私有Registry：yum安装，容器安装，上传下载镜像；Harbor：Harbor特性，下载Harbor，硬件要求，软件依赖，Docker Compose，安装Harbor，登录Harbor，停止Harbor</p>">
        <!-- OG Tags -->
<meta property="og:url" content="/docker-registry.html"/>
<meta property="og:title" content="来玩魔王的咚 | Docker 私有Registry" />
<meta property="og:description" content="<p>私有Registry：yum安装，容器安装，上传下载镜像；Harbor：Harbor特性，下载Harbor，硬件要求，软件依赖，Docker Compose，安装Harbor，登录Harbor，停止Harbor</p>" />
        <!-- favicon -->
        <link rel="icon" type="image/png" href="/images/mowang.png">
        <!-- moment.js for date formatting -->
        <script src="/theme/js/moment.js"></script>
        <!-- css -->
        <link rel="stylesheet" type="text/css" href="/theme/css/main.css" />
        <!-- 左边的menu，如果页面高度不够，就跟着滚动，否则文章分类显示不全 -->
        <link rel="stylesheet" type="text/css" href="/theme/css/mycss/menu.css" />
		<script>
			
                /*! grunt-grunticon Stylesheet Loader - v2.1.2 | https://github.com/filamentgroup/grunticon | (c) 2015 Scott Jehl, Filament Group, Inc. | MIT license. */
    
    (function(e){function t(t,n,r,o){"use strict";function a(){for(var e,n=0;u.length>n;n++)u[n].href&&u[n].href.indexOf(t)>-1&&(e=!0);e?i.media=r||"all":setTimeout(a)}var i=e.document.createElement("link"),l=n||e.document.getElementsByTagName("script")[0],u=e.document.styleSheets;return i.rel="stylesheet",i.href=t,i.media="only x",i.onload=o||null,l.parentNode.insertBefore(i,l),a(),i}var n=function(r,o){"use strict";if(r&&3===r.length){var a=e.navigator,i=e.Image,l=!(!document.createElementNS||!document.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect||!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1")||e.opera&&-1===a.userAgent.indexOf("Chrome")||-1!==a.userAgent.indexOf("Series40")),u=new i;u.onerror=function(){n.method="png",n.href=r[2],t(r[2])},u.onload=function(){var e=1===u.width&&1===u.height,a=r[e&&l?0:e?1:2];n.method=e&&l?"svg":e?"datapng":"png",n.href=a,t(a,null,null,o)},u.src="",document.documentElement.className+=" grunticon"}};n.loadCSS=t,e.grunticon=n})(this);(function(e,t){"use strict";var n=t.document,r="grunticon:",o=function(e){if(n.attachEvent?"complete"===n.readyState:"loading"!==n.readyState)e();else{var t=!1;n.addEventListener("readystatechange",function(){t||(t=!0,e())},!1)}},a=function(e){return t.document.querySelector('link[href$="'+e+'"]')},c=function(e){var t,n,o,a,c,i,u={};if(t=e.sheet,!t)return u;n=t.cssRules?t.cssRules:t.rules;for(var l=0;n.length>l;l++)o=n[l].cssText,a=r+n[l].selectorText,c=o.split(");")[0].match(/US\-ASCII\,([^"']+)/),c&&c[1]&&(i=decodeURIComponent(c[1]),u[a]=i);return u},i=function(e){var t,o,a;o="data-grunticon-embed";for(var c in e)if(a=c.slice(r.length),t=n.querySelectorAll(a+"["+o+"]"),t.length)for(var i=0;t.length>i;i++)t[i].innerHTML=e[c],t[i].style.backgroundImage="none",t[i].removeAttribute(o);return t},u=function(t){"svg"===e.method&&o(function(){i(c(a(e.href))),"function"==typeof t&&t()})};e.embedIcons=i,e.getCSS=a,e.getIcons=c,e.ready=o,e.svgLoadedCallback=u,e.embedSVG=u})(grunticon,this);
                
                grunticon(["/theme/css/icons.data.svg.css", "/theme/css/icons.data.png.css", "/theme/css/icons.fallback.css"]);
            </script>
        <noscript><link href="/theme/css/icons.fallback.css" rel="stylesheet"></noscript>
        <!-- menu toggle javascript -->
        <script type="text/javascript">
            document.addEventListener("DOMContentLoaded", initMenu);
            
            function initMenu(){
                var menu = document.getElementById("menu");
                var menulink = document.getElementById("menu-link");
                menulink.addEventListener("click", function toggleMenu(){
                        window.event.preventDefault();
                        menulink.classList.toggle('active');
                        menu.classList.toggle('active');              
                    });
            };
        </script>
        <!-- 不蒜子 -->
        <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

    <meta name="description" content="<p>私有Registry：yum安装，容器安装，上传下载镜像；Harbor：Harbor特性，下载Harbor，硬件要求，软件依赖，Docker Compose，安装Harbor，登录Harbor，停止Harbor</p>" />

    <meta name="tags" content="docker" />
    <meta name="tags" content="harbor" />
  <!-- 替换部分base的样式，看文章时，要再宽一点，右边有很多空间可以撑开 -->
  <link rel="stylesheet" type="text/css" href="/theme/css/mycss/article.css" />

</head>
<body>
    <div role="banner" id="masthead">
        <header>
            <a href="/"><img src="/images/mowang.png" alt="McManus Logo"></a>
                <h1>来玩魔王的咚@骑士救兵</h1>
            <a href="#menu" id="menu-link">more stuff</a>
            <nav id="menu">
                <ul>
                        <li><a href="/tags">tags</a></li>
                            <li><a href="/category/cloud.html">Cloud</a></li>
                            <li class="active"><a href="/category/docker.html">Docker</a></li>
                            <li><a href="/category/go.html">Go</a></li>
                            <li><a href="/category/linux.html">Linux</a></li>
                            <li><a href="/category/python.html">Python</a></li>
                            <li><a href="/category/xue-xi-bi-ji.html">学习笔记</a></li>
                            <li><a href="/category/yun-wei-zi-dong-hua.html">运维自动化</a></li>
                </ul>
            </nav>
        </header>
    </div>
        <div class="page" role="main">
  <div class="article" role="article">
    <article>
        <footer>
            <a name="top"></a>
            <p>
              <time datetime=" 2020-07-22 16:00:00+08:00">
                <script>document.write(moment('2020-07-22 16:00:00+08:00').format('LL'));</script>
              </time>
              ~
              <time datetime=" 2020-07-22 16:00:00+08:00">
                <script>document.write(moment('2020-07-22 16:00:00+08:00').format('LL'));</script>
              </time>
            </p>
        </footer>
        <header>
          <h2>
            Docker 私有Registry
          </h2>
        </header>
      <div class="content">
         <div class="toc">
<ul>
<li><a href="#si-you-registry">私有Registry</a><ul>
<li><a href="#yum-an-zhuang">YUM安装</a></li>
<li><a href="#rong-qi-an-zhuang">容器安装</a></li>
<li><a href="#shang-chuan-jing-xiang">上传镜像</a></li>
<li><a href="#xia-zai-jing-xiang">下载镜像</a></li>
</ul>
</li>
<li><a href="#harbor">Harbor</a><ul>
<li><a href="#harbor-te-xing">Harbor特性</a></li>
<li><a href="#an-zhuang-zhun-bei">安装准备</a></li>
<li><a href="#docker-compose">Docker Compose</a></li>
<li><a href="#an-zhuang-harbor">安装 Harbor</a></li>
<li><a href="#deng-lu-harbor">登录 Harbor</a></li>
<li><a href="#ting-zhi-harbor">停止 Harbor</a></li>
</ul>
</li>
</ul>
</div>
<p>Registry用于保存docker镜像，包括镜像的层次结构和元数据。用户可以自建Registry，也可使用官方的Docker Hub。  </p>
<p><strong>Docker Registry 分类：</strong></p>
<ul>
<li>Sponsor Registry: 第三方的registry，供客户和Docker社区使用</li>
<li>Mirror Registry: 第三方的registryy，只让客户使用</li>
<li>Vendor Registry: 由发布Docker镜像的供应商提供的registry</li>
<li>Private Registry: 通过设有防火墙和额外的安全层的私有实体提供的registry</li>
</ul>
<h3 id="si-you-registry"><a class="toclink" href="#si-you-registry">私有Registry</a></h3>
<p>使用前先要将服务部署到服务器上。  </p>
<h4 id="yum-an-zhuang"><a class="toclink" href="#yum-an-zhuang">YUM安装</a></h4>
<p>可以通过yum安装：</p>
<div class="highlight"><pre><span></span><code>yum install docker-registry
yum install docker-distribution
</code></pre></div>

<p>上面两个命令都会安装docker-distribution只要执行一个就好了。  </p>
<p>软件包的信息：</p>
<div class="highlight"><pre><span></span><code>$ yum info docker-distribution
已加载插件：fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
可安装的软件包
名称    ：docker-distribution
架构    ：x86_64
版本    ：2.6.2
发布    ：2.git48294d9.el7
大小    ：3.5 M
源    ：extras/7/x86_64
简介    ： Docker toolset to pack, ship, store, and deliver content
网址    ：https://github.com/docker/distribution
协议    ： ASL <span class="m">2</span>.0
描述    ： Docker toolset to pack, ship, store, and deliver content

$ 
</code></pre></div>

<p>这个就不装了，因为还可以将服务安装在容器中运行。  </p>
<h4 id="rong-qi-an-zhuang"><a class="toclink" href="#rong-qi-an-zhuang">容器安装</a></h4>
<p>docker官方也提供了容器，基于容器提供Registry服务。  </p>
<p>下载镜像：</p>
<div class="highlight"><pre><span></span><code>$ docker image pull registry
Using default tag: latest
latest: Pulling from library/registry
c87736221ed0: Pull <span class="nb">complete</span> 
1cc8e0bb44df: Pull <span class="nb">complete</span> 
54d33bcb37f5: Pull <span class="nb">complete</span> 
e8afc091c171: Pull <span class="nb">complete</span> 
b4541f6d3db6: Pull <span class="nb">complete</span> 
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146
Status: Downloaded newer image <span class="k">for</span> registry:latest
$ 
</code></pre></div>

<p>启动容器：</p>
<div class="highlight"><pre><span></span><code>docker run -d -p <span class="m">5000</span>:5000 --restart always --name registry registry
</code></pre></div>

<h5 id="pei-zhi-wen-jian"><a class="toclink" href="#pei-zhi-wen-jian">配置文件</a></h5>
<p>查看registry的配置文件：</p>
<div class="highlight"><pre><span></span><code>$ docker container <span class="nb">exec</span> -it registry cat /etc/docker/registry/config.yml
version: <span class="m">0</span>.1
log:
  fields:
    service: registry
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
http:
  addr: :5000
  headers:
    X-Content-Type-Options: <span class="o">[</span>nosniff<span class="o">]</span>
health:
  storagedriver:
    enabled: <span class="nb">true</span>
    interval: 10s
    threshold: <span class="m">3</span>
$ 
</code></pre></div>

<p>这里是默认的配置文件。配置文件是通过CMD命令指定的，默认的dockerfile的CMD指令如下：</p>
<div class="highlight"><pre><span></span><code><span class="k">CMD</span><span class="w"> </span><span class="p">[</span><span class="s2">&quot;/etc/docker/registry/config.yml&quot;</span><span class="p">]</span>
</code></pre></div>

<h5 id="jing-xiang-cun-fang-de-wei-zhi"><a class="toclink" href="#jing-xiang-cun-fang-de-wei-zhi">镜像存放的位置</a></h5>
<p>镜像Dockerfile中有一条VOLUME指令，这个路径就是容器是存放镜像的路径：</p>
<div class="highlight"><pre><span></span><code><span class="k">VOLUME</span><span class="w"> </span><span class="p">[</span><span class="s2">&quot;/var/lib/registry&quot;</span><span class="p">]</span>
</code></pre></div>

<p>启动镜像时，可以使用-v参数，指定宿主机的目录。  </p>
<h4 id="shang-chuan-jing-xiang"><a class="toclink" href="#shang-chuan-jing-xiang">上传镜像</a></h4>
<p>上传镜像前，先要给镜像打标：</p>
<div class="highlight"><pre><span></span><code>$ docker push busybox loclhost:5000/busybox
</code></pre></div>

<p>这里要准备将本地的busybox推送到服务器loclhost:5000。这里省略了仓库的用户名，没有用户名就是一个顶层仓库。  </p>
<p>推送：</p>
<div class="highlight"><pre><span></span><code>$ docker push localhost:5000/busybox
The push refers to repository <span class="o">[</span>localhost:5000/busybox<span class="o">]</span>
0d315111b484: Pushed 
latest: digest: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649 size: <span class="m">527</span>
$ 
</code></pre></div>

<p>不往本机lo接口推，也就是服务器地址不使用localhost或127.0.0.1。而是向本机的网卡地址推。就像其他主机要向本机的registry推送一样了。然后会产生如下的错误：</p>
<div class="highlight"><pre><span></span><code>$ docker push <span class="m">192</span>.168.24.170:5000/busybox
The push refers to repository <span class="o">[</span><span class="m">192</span>.168.24.170:5000/busybox<span class="o">]</span>
Get https://192.168.24.170:5000/v2/: http: server gave HTTP response to HTTPS client
$ 
</code></pre></div>

<p>这里的问题是，docker默认是使用https协议工作的，而registry服务器的响应是http协议。解决的办法有两个。<br>
第一个方法是修改registry来适应docker，registry服务器改为https协议<br>
第二个方法是修改docker来使用registry，将registry服务器地址加入到docker的insecure-registries中去  </p>
<h5 id="pei-zhi-insecure-registries"><a class="toclink" href="#pei-zhi-insecure-registries">配置insecure-registries</a></h5>
<p>修改配置文件，然后重启加载后就可以推送上去了：</p>
<div class="highlight"><pre><span></span><code>$ cat /etc/docker/daemon.json
<span class="o">{</span>
    <span class="s2">&quot;registry-mirrors&quot;</span>: <span class="o">[</span><span class="s2">&quot;http://hub-mirror.c.163.com&quot;</span>, <span class="s2">&quot;https://docker.mirrors.ustc.edu.cn&quot;</span><span class="o">]</span>,
    <span class="s2">&quot;insecure-registries&quot;</span>: <span class="o">[</span><span class="s2">&quot;192.168.24.170:5000&quot;</span><span class="o">]</span>
<span class="o">}</span>
$ systemctl reload docker
$ docker push <span class="m">192</span>.168.24.170:5000/busybox
The push refers to repository <span class="o">[</span><span class="m">192</span>.168.24.170:5000/busybox<span class="o">]</span>
0d315111b484: Layer already exists 
latest: digest: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649 size: <span class="m">527</span>
$ 
</code></pre></div>

<h4 id="xia-zai-jing-xiang"><a class="toclink" href="#xia-zai-jing-xiang">下载镜像</a></h4>
<p>指定Registry下载之前上传的镜像：</p>
<div class="highlight"><pre><span></span><code>$ docker pull <span class="m">192</span>.168.24.170:5000/busybox
Using default tag: latest
latest: Pulling from busybox
ee153a04d683: Pull <span class="nb">complete</span> 
Digest: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649
Status: Downloaded newer image <span class="k">for</span> <span class="m">192</span>.168.24.170:5000/busybox:latest
$ 
</code></pre></div>

<h3 id="harbor"><a class="toclink" href="#harbor">Harbor</a></h3>
<p>Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器。  </p>
<h4 id="harbor-te-xing"><a class="toclink" href="#harbor-te-xing">Harbor特性</a></h4>
<p><strong>基于角色的访问控制</strong>：用户与Docker镜像仓库通过“项目”进行组织管理，一个用户可以对多个镜像仓库在同一命名空间（project）里有不同的权限。<br>
<strong>镜像复制</strong>：镜像可以在多个Registry实例中复制（同步）。尤其适合于负载均衡，高可用，混合云和多云的场景。<br>
<strong>图形化用户界面</strong>：用户可以通过浏览器来浏览，检索当前Docker镜像仓库，管理项目和命名空间。<br>
<strong>AD/LDAP 支持</strong>：Harbor可以集成企业内部已有的AD/LDAP，用于鉴权认证管理。<br>
<strong>审计管理</strong>：所有针对镜像仓库的操作都可以被记录追溯，用于审计管理。<br>
<strong>国际化</strong>：已拥有英文、中文、德文、日文和俄文的本地化版本。更多的语言将会添加进来。<br>
<strong>RESTful API</strong>：RESTful API 提供给管理员对于Harbor更多的操控, 使得与其它管理软件集成变得更容易。<br>
<strong>部署简单</strong>：提供在线和离线两种安装工具， 也可以安装到vSphere平台(OVA方式)虚拟设备。  </p>
<h4 id="an-zhuang-zhun-bei"><a class="toclink" href="#an-zhuang-zhun-bei">安装准备</a></h4>
<p>github项目地址：<br>
https://github.com/vmware/harbor<br>
这是一个vmware的开源项目，实际会跳转到下面这个地址：<br>
https://github.com/goharbor/harbor  </p>
<h5 id="xia-zai-harbor"><a class="toclink" href="#xia-zai-harbor">下载 harbor</a></h5>
<p>查看项目的README，Features的内容上面提过了，这里主要看<strong>Install &amp; Run</strong>部分的内容。  </p>
<p>首先是下载<br>
Harbor release：<br>
https://github.com/goharbor/harbor/releases  </p>
<div class="highlight"><pre><span></span><code>$ wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.2-rc1.tgz
</code></pre></div>

<h5 id="an-zhuang-pei-zhi-xiang-dao"><a class="toclink" href="#an-zhuang-pei-zhi-xiang-dao">安装配置向导</a></h5>
<p>Installation &amp; Configuration Guide：<br>
https://github.com/goharbor/harbor/blob/master/docs/installation_guide.md  </p>
<p>硬件要求：</p>
<table>
<thead>
<tr>
<th align="left">Resource</th>
<th align="left">Capacity</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">CPU</td>
<td align="left">minimal 2 CPU</td>
<td align="left">4 CPU is preferred</td>
</tr>
<tr>
<td align="left">Mem</td>
<td align="left">minimal 4GB</td>
<td align="left">8GB is preferred</td>
</tr>
<tr>
<td align="left">Disk</td>
<td align="left">minimal 40GB</td>
<td align="left">160GB is preferred</td>
</tr>
</tbody>
</table>
<p>软件要求：</p>
<table>
<thead>
<tr>
<th align="left">Software</th>
<th align="left">Version</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Docker engine</td>
<td align="left">version 17.06.0-ce+ or higher</td>
<td align="left">For installation instructions, please refer to: docker engine doc</td>
</tr>
<tr>
<td align="left">Docker Compose</td>
<td align="left">version 1.18.0 or higher</td>
<td align="left">For installation instructions, please refer to: docker compose doc</td>
</tr>
<tr>
<td align="left">Openssl</td>
<td align="left">latest is preferred</td>
<td align="left">Generate certificate and keys for Harbor</td>
</tr>
</tbody>
</table>
<p>安装步骤：</p>
<ol>
<li>Download the installer;</li>
<li>Configure harbor.yml;</li>
<li>Run install.sh to install and start Harbor;</li>
</ol>
<p>下载完之后，先解压：</p>
<div class="highlight"><pre><span></span><code>$ tar xvf harbor-offline-installer-v1.8.1.tar -C /opt
harbor/harbor.v1.8.1.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/harbor.yml
$ 
</code></pre></div>

<p>下载的文件在解压后就不需要了。解压后的文件在安装完成后也都是不需要的。所以下载到哪里，解压到哪里其实都不重要。建议可以解压到 /opt 或 /usr/local 这两个目录里。  </p>
<h5 id="an-zhuang-bao-zhong-de-jing-xiang"><a class="toclink" href="#an-zhuang-bao-zhong-de-jing-xiang">安装包中的镜像</a></h5>
<p>解压后的文件中，有一个文件harbor.v1.8.1.tar.gz。这个是被导出的docker镜像。还记得docker save命令吧，可以打包导出多个镜像并完成压缩：</p>
<div class="highlight"><pre><span></span><code>$ docker save myimg/httpd:v1 myimg/httpd:v2 <span class="p">|</span> gzip &gt; myimage_latest.tar.gz
</code></pre></div>

<p>这个文件应该就是这么来的。之后的安装过程中，则是会把这个文件里的所有镜像做一次批量导入：</p>
<div class="highlight"><pre><span></span><code>$ docker load -i myimage_latest.tar.gz
</code></pre></div>

<p>在安装时执行的install.sh脚本里有解压并导入镜像的语句：</p>
<div class="highlight"><pre><span></span><code><span class="k">if</span> <span class="o">[</span> -f harbor*.tar.gz <span class="o">]</span>
<span class="k">then</span>
        h2 <span class="s2">&quot;[Step </span><span class="nv">$item</span><span class="s2">]: loading Harbor images ...&quot;</span><span class="p">;</span> <span class="nb">let</span> <span class="nv">item</span><span class="o">+=</span><span class="m">1</span>
        docker load -i ./harbor*.tar.gz
<span class="k">fi</span>
</code></pre></div>

<h5 id="an-zhuang-de-yi-lai-he-guo-cheng"><a class="toclink" href="#an-zhuang-de-yi-lai-he-guo-cheng">安装的依赖和过程</a></h5>
<p>Harbor的安装，就是给当前的主机安装很多容器，并且把这些容器都启动起来。启动Harbor就是用docker-compose把这些容器的启动起来，而关闭harbor也是通过docker-compose来把容器一次关闭。之所以需要借助docker-compose，因为harbor是由很多容器协同过程的，容器之间又依赖关系，这些都需要docker-compose这个单机编排工具来协调。  </p>
<p>所以安装harbor前，需要安装好docker-compose，才能实现本地的容器的编排。需要安装好docker，才能把本地的镜像启动起来。镜像就在下载解压的文件中。并且还需要启动docker，这样才能运行容器。<br>
准备工作完成后，就是执行harbor准备的install.sh脚本，在本地加载好镜像，通过docker-compose把这些镜像依次启动起来，并且运行在本地的docker上。  </p>
<p>修改harbor.yml配置文件，主机名一定要改掉，最好使用本机的域名，如果没有域名那么就用本机的IP地址。没改的话，会有如下的错误提示：</p>
<div class="highlight"><pre><span></span><code>$ ./install.sh 
➜ Please <span class="nb">set</span> hostname and other necessary attributes <span class="k">in</span> harbor.yml first. DO NOT use localhost or <span class="m">127</span>.0.0.1 <span class="k">for</span> hostname, because Harbor needs to be accessed by external clients.
Please <span class="nb">set</span> --with-notary <span class="k">if</span> needs <span class="nb">enable</span> Notary <span class="k">in</span> Harbor, and <span class="nb">set</span> ui_url_protocol/ssl_cert/ssl_cert_key <span class="k">in</span> harbor.yml bacause notary must run under https. 
Please <span class="nb">set</span> --with-clair <span class="k">if</span> needs <span class="nb">enable</span> Clair <span class="k">in</span> Harbor
Please <span class="nb">set</span> --with-chartmuseum <span class="k">if</span> needs <span class="nb">enable</span> Chartmuseum <span class="k">in</span> Harbor
$ 
</code></pre></div>

<p>检查发现没有安装docker：</p>
<div class="highlight"><pre><span></span><code>$ ./install.sh 

<span class="o">[</span>Step <span class="m">0</span><span class="o">]</span>: checking installation environment ...
✖ Need to install docker<span class="o">(</span><span class="m">17</span>.06.0+<span class="o">)</span> first and run this script again.
<span class="o">[</span>root@Harbor harbor<span class="o">]</span><span class="c1"># </span>
</code></pre></div>

<p>检查发现没有安装docker-compose：</p>
<div class="highlight"><pre><span></span><code>$ ./install.sh 

<span class="o">[</span>Step <span class="m">0</span><span class="o">]</span>: checking installation environment ...

Note: docker version: <span class="m">19</span>.03.1
✖ Need to install docker-compose<span class="o">(</span><span class="m">1</span>.18.0+<span class="o">)</span> by yourself first and run this script again.
$ 
</code></pre></div>

<p>检查发现docker没有启动：</p>
<div class="highlight"><pre><span></span><code>$ ./install.sh 

<span class="o">[</span>Step <span class="m">0</span><span class="o">]</span>: checking installation environment ...

Note: docker version: <span class="m">19</span>.03.1

Note: docker-compose version: <span class="m">1</span>.18.0

<span class="o">[</span>Step <span class="m">1</span><span class="o">]</span>: loading Harbor images ...
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
$ 
</code></pre></div>

<h4 id="docker-compose"><a class="toclink" href="#docker-compose">Docker Compose</a></h4>
<p>Docker的单机编排工具。官方文档：<br>
https://docs.docker.com/compose/  </p>
<p>为了简化harbor的安装和部署，所以harbor做成了在容器中运行的应用。但是harbor的运行还依赖很多其他的应用，所以需要编排几个容器来协同工作。所以harbor的部署和使用时需要借助Docker的单机编排工具Docker Compose。  </p>
<p>安装docker-compose，位于epel源中：</p>
<div class="highlight"><pre><span></span><code>yum install docker-compose
</code></pre></div>

<h5 id="compose-mu-ban-wen-jian"><a class="toclink" href="#compose-mu-ban-wen-jian">Compose模板文件</a></h5>
<p>模板文件是使用Compose的核心，设计的指令关键字也有很多，默认的模板文件名称为docker-compose.yml，格式为YAML格式。<br>
这个不是重点，能安装使用harbor就好了，不过还是简单了解一下。<br>
要使用docker-compose就要写一个编排脚本，和dockerfile类似，也是有很多指令。定义要启动的每一个容器，指明依赖关系，这样被依赖的容器需要先启动。关闭容器的时候也要对称，先把没有被依赖的容器关闭掉。<br>
顺便就来看下harbor的docker-compose.yml文件：</p>
<div class="highlight"><pre><span></span><code><span class="nt">version</span><span class="p">:</span><span class="w"> </span><span class="s">&#39;2.3&#39;</span><span class="w">  </span><span class="c1"># docker-compose的版本</span><span class="w"></span>
<span class="nt">services</span><span class="p">:</span><span class="w">  </span><span class="c1"># 定义一个服务</span><span class="w"></span>
<span class="w">  </span><span class="nt">log</span><span class="p">:</span><span class="w">  </span><span class="c1"># 服务的名称，服务是通过容器来提供的，具体就是下面的设置</span><span class="w"></span>
<span class="w">    </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">goharbor/harbor-log:v1.8.1</span><span class="w">  </span><span class="c1"># 指定容器的镜像，也可以用build指令通过dockerfile创建</span><span class="w"></span>
<span class="w">    </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">harbor-log</span><span class="w">  </span><span class="c1"># 生成的容器的名称</span><span class="w"></span>
<span class="w">    </span><span class="nt">restart</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">always</span><span class="w">  </span><span class="c1"># 容器自动重启</span><span class="w"></span>
<span class="w">    </span><span class="nt">dns_search</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">.</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_drop</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ALL</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_add</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">CHOWN</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DAC_OVERRIDE</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETGID</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETUID</span><span class="w"></span>
<span class="w">    </span><span class="nt">volumes</span><span class="p">:</span><span class="w">  </span><span class="c1"># 定义卷</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/var/log/harbor/:/var/log/docker/:z</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/log/:/etc/logrotate.d/:z</span><span class="w"></span>
<span class="w">    </span><span class="nt">ports</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">127.0.0.1:1514:10514</span><span class="w"></span>
<span class="w">    </span><span class="nt">networks</span><span class="p">:</span><span class="w">  </span><span class="c1"># 加入的网络</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">harbor</span><span class="w"></span>
<span class="w">  </span><span class="nt">registry</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">goharbor/registry-photon:v2.7.1-patch-2819-v1.8.1</span><span class="w"></span>
<span class="w">    </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">registry</span><span class="w"></span>
<span class="w">    </span><span class="nt">restart</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">always</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_drop</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ALL</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_add</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">CHOWN</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETGID</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETUID</span><span class="w"></span>
<span class="w">    </span><span class="nt">volumes</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/data/registry:/storage:z</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/registry/:/etc/registry/:z</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">bind</span><span class="w"></span>
<span class="w">        </span><span class="nt">source</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/data/secret/registry/root.crt</span><span class="w"></span>
<span class="w">        </span><span class="nt">target</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/etc/registry/root.crt</span><span class="w"></span>
<span class="w">    </span><span class="nt">networks</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">harbor</span><span class="w"></span>
<span class="w">    </span><span class="nt">dns_search</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">.</span><span class="w"></span>
<span class="w">    </span><span class="nt">depends_on</span><span class="p">:</span><span class="w">  </span><span class="c1"># 依赖的容器名称</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">log</span><span class="w"></span>
<span class="w">    </span><span class="nt">logging</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="nt">driver</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;syslog&quot;</span><span class="w"></span>
<span class="w">      </span><span class="nt">options</span><span class="p">:</span><span class="w">  </span>
<span class="w">        </span><span class="nt">syslog-address</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;tcp://127.0.0.1:1514&quot;</span><span class="w"></span>
<span class="w">        </span><span class="nt">tag</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;registry&quot;</span><span class="w"></span>
<span class="w">  </span><span class="nt">registryctl</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">goharbor/harbor-registryctl:v1.8.1</span><span class="w"></span>
<span class="w">    </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">registryctl</span><span class="w"></span>
<span class="w">    </span><span class="nt">env_file</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/registryctl/env</span><span class="w"></span>
<span class="w">    </span><span class="nt">restart</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">always</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_drop</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ALL</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_add</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">CHOWN</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETGID</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETUID</span><span class="w"></span>
<span class="w">    </span><span class="nt">volumes</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/data/registry:/storage:z</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/registry/:/etc/registry/:z</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">bind</span><span class="w"></span>
<span class="w">        </span><span class="nt">source</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/registryctl/config.yml</span><span class="w"></span>
<span class="w">        </span><span class="nt">target</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/etc/registryctl/config.yml</span><span class="w"></span>
<span class="w">    </span><span class="nt">networks</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">harbor</span><span class="w"></span>
<span class="w">    </span><span class="nt">dns_search</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">.</span><span class="w"></span>
<span class="w">    </span><span class="nt">depends_on</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">log</span><span class="w"></span>
<span class="w">    </span><span class="nt">logging</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="nt">driver</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;syslog&quot;</span><span class="w"></span>
<span class="w">      </span><span class="nt">options</span><span class="p">:</span><span class="w">  </span>
<span class="w">        </span><span class="nt">syslog-address</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;tcp://127.0.0.1:1514&quot;</span><span class="w"></span>
<span class="w">        </span><span class="nt">tag</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;registryctl&quot;</span><span class="w"></span>
<span class="w">  </span><span class="nt">postgresql</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">goharbor/harbor-db:v1.8.1</span><span class="w"></span>
<span class="w">    </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">harbor-db</span><span class="w"></span>
<span class="w">    </span><span class="nt">restart</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">always</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_drop</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ALL</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_add</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">CHOWN</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">DAC_OVERRIDE</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETGID</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETUID</span><span class="w"></span>
<span class="w">    </span><span class="nt">volumes</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/data/database:/var/lib/postgresql/data:z</span><span class="w"></span>
<span class="w">    </span><span class="nt">networks</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="nt">harbor</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">dns_search</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">.</span><span class="w"></span>
<span class="w">    </span><span class="nt">env_file</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/db/env</span><span class="w"></span>
<span class="w">    </span><span class="nt">depends_on</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">log</span><span class="w"></span>
<span class="w">    </span><span class="nt">logging</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="nt">driver</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;syslog&quot;</span><span class="w"></span>
<span class="w">      </span><span class="nt">options</span><span class="p">:</span><span class="w">  </span>
<span class="w">        </span><span class="nt">syslog-address</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;tcp://127.0.0.1:1514&quot;</span><span class="w"></span>
<span class="w">        </span><span class="nt">tag</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;postgresql&quot;</span><span class="w"></span>
<span class="w">  </span><span class="nt">core</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">goharbor/harbor-core:v1.8.1</span><span class="w"></span>
<span class="w">    </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">harbor-core</span><span class="w"></span>
<span class="w">    </span><span class="nt">env_file</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/core/env</span><span class="w"></span>
<span class="w">    </span><span class="nt">restart</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">always</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_drop</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ALL</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_add</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETGID</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETUID</span><span class="w"></span>
<span class="w">    </span><span class="nt">volumes</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/data/ca_download/:/etc/core/ca/:z</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/data/psc/:/etc/core/token/:z</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/data/:/data/:z</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/core/certificates/:/etc/core/certificates/:z</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">bind</span><span class="w"></span>
<span class="w">        </span><span class="nt">source</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/core/app.conf</span><span class="w"></span>
<span class="w">        </span><span class="nt">target</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/etc/core/app.conf</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">bind</span><span class="w"></span>
<span class="w">        </span><span class="nt">source</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/data/secret/core/private_key.pem</span><span class="w"></span>
<span class="w">        </span><span class="nt">target</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/etc/core/private_key.pem</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">bind</span><span class="w"></span>
<span class="w">        </span><span class="nt">source</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/data/secret/keys/secretkey</span><span class="w"></span>
<span class="w">        </span><span class="nt">target</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/etc/core/key</span><span class="w"></span>
<span class="w">    </span><span class="nt">networks</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="nt">harbor</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">dns_search</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">.</span><span class="w"></span>
<span class="w">    </span><span class="nt">depends_on</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">log</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">registry</span><span class="w"></span>
<span class="w">    </span><span class="nt">logging</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="nt">driver</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;syslog&quot;</span><span class="w"></span>
<span class="w">      </span><span class="nt">options</span><span class="p">:</span><span class="w">  </span>
<span class="w">        </span><span class="nt">syslog-address</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;tcp://127.0.0.1:1514&quot;</span><span class="w"></span>
<span class="w">        </span><span class="nt">tag</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;core&quot;</span><span class="w"></span>
<span class="w">  </span><span class="nt">portal</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">goharbor/harbor-portal:v1.8.1</span><span class="w"></span>
<span class="w">    </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">harbor-portal</span><span class="w"></span>
<span class="w">    </span><span class="nt">restart</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">always</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_drop</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ALL</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_add</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">CHOWN</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETGID</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETUID</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">NET_BIND_SERVICE</span><span class="w"></span>
<span class="w">    </span><span class="nt">networks</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">harbor</span><span class="w"></span>
<span class="w">    </span><span class="nt">dns_search</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">.</span><span class="w"></span>
<span class="w">    </span><span class="nt">depends_on</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">log</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">core</span><span class="w"></span>
<span class="w">    </span><span class="nt">logging</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="nt">driver</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;syslog&quot;</span><span class="w"></span>
<span class="w">      </span><span class="nt">options</span><span class="p">:</span><span class="w"></span>
<span class="w">        </span><span class="nt">syslog-address</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;tcp://127.0.0.1:1514&quot;</span><span class="w"></span>
<span class="w">        </span><span class="nt">tag</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;portal&quot;</span><span class="w"></span>

<span class="w">  </span><span class="nt">jobservice</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">goharbor/harbor-jobservice:v1.8.1</span><span class="w"></span>
<span class="w">    </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">harbor-jobservice</span><span class="w"></span>
<span class="w">    </span><span class="nt">env_file</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/jobservice/env</span><span class="w"></span>
<span class="w">    </span><span class="nt">restart</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">always</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_drop</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ALL</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_add</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">CHOWN</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETGID</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETUID</span><span class="w"></span>
<span class="w">    </span><span class="nt">volumes</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/data/job_logs:/var/log/jobs:z</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">bind</span><span class="w"></span>
<span class="w">        </span><span class="nt">source</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/jobservice/config.yml</span><span class="w"></span>
<span class="w">        </span><span class="nt">target</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/etc/jobservice/config.yml</span><span class="w"></span>
<span class="w">    </span><span class="nt">networks</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">harbor</span><span class="w"></span>
<span class="w">    </span><span class="nt">dns_search</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">.</span><span class="w"></span>
<span class="w">    </span><span class="nt">depends_on</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">redis</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">core</span><span class="w"></span>
<span class="w">    </span><span class="nt">logging</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="nt">driver</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;syslog&quot;</span><span class="w"></span>
<span class="w">      </span><span class="nt">options</span><span class="p">:</span><span class="w"></span>
<span class="w">        </span><span class="nt">syslog-address</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;tcp://127.0.0.1:1514&quot;</span><span class="w"></span>
<span class="w">        </span><span class="nt">tag</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;jobservice&quot;</span><span class="w"></span>
<span class="w">  </span><span class="nt">redis</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">goharbor/redis-photon:v1.8.1</span><span class="w"></span>
<span class="w">    </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">redis</span><span class="w"></span>
<span class="w">    </span><span class="nt">restart</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">always</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_drop</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ALL</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_add</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">CHOWN</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETGID</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETUID</span><span class="w"></span>
<span class="w">    </span><span class="nt">volumes</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">/data/redis:/var/lib/redis</span><span class="w"></span>
<span class="w">    </span><span class="nt">networks</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="nt">harbor</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">dns_search</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">.</span><span class="w"></span>
<span class="w">    </span><span class="nt">depends_on</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">log</span><span class="w"></span>
<span class="w">    </span><span class="nt">logging</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="nt">driver</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;syslog&quot;</span><span class="w"></span>
<span class="w">      </span><span class="nt">options</span><span class="p">:</span><span class="w"></span>
<span class="w">        </span><span class="nt">syslog-address</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;tcp://127.0.0.1:1514&quot;</span><span class="w"></span>
<span class="w">        </span><span class="nt">tag</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;redis&quot;</span><span class="w"></span>
<span class="w">  </span><span class="nt">proxy</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">goharbor/nginx-photon:v1.8.1</span><span class="w"></span>
<span class="w">    </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">nginx</span><span class="w"></span>
<span class="w">    </span><span class="nt">restart</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">always</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_drop</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ALL</span><span class="w"></span>
<span class="w">    </span><span class="nt">cap_add</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">CHOWN</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETGID</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SETUID</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">NET_BIND_SERVICE</span><span class="w"></span>
<span class="w">    </span><span class="nt">volumes</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./common/config/nginx:/etc/nginx:z</span><span class="w"></span>
<span class="w">    </span><span class="nt">networks</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">harbor</span><span class="w"></span>
<span class="w">    </span><span class="nt">dns_search</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">.</span><span class="w"></span>
<span class="w">    </span><span class="nt">ports</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">80:80</span><span class="w"></span>
<span class="w">    </span><span class="nt">depends_on</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">postgresql</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">registry</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">core</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">portal</span><span class="w"></span>
<span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">log</span><span class="w"></span>
<span class="w">    </span><span class="nt">logging</span><span class="p">:</span><span class="w"></span>
<span class="w">      </span><span class="nt">driver</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;syslog&quot;</span><span class="w"></span>
<span class="w">      </span><span class="nt">options</span><span class="p">:</span><span class="w">  </span>
<span class="w">        </span><span class="nt">syslog-address</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;tcp://127.0.0.1:1514&quot;</span><span class="w"></span>
<span class="w">        </span><span class="nt">tag</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;proxy&quot;</span><span class="w"></span>
<span class="nt">networks</span><span class="p">:</span><span class="w"></span>
<span class="w">  </span><span class="nt">harbor</span><span class="p">:</span><span class="w"></span>
<span class="w">    </span><span class="nt">external</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">false</span><span class="w"></span>
</code></pre></div>

<h4 id="an-zhuang-harbor"><a class="toclink" href="#an-zhuang-harbor">安装 Harbor</a></h4>
<p>安装前，需要去修改一下harbor.yml这个文件的配置，至少要把主机名改掉，之前已经说过了。其他配置按需要修改，不改也能够安装了。  </p>
<p>一切准备就行，就可以安装了：</p>
<div class="highlight"><pre><span></span><code>$ ./install.sh 

<span class="o">[</span>Step <span class="m">0</span><span class="o">]</span>: checking installation environment ...

Note: docker version: <span class="m">19</span>.03.1

Note: docker-compose version: <span class="m">1</span>.18.0

<span class="o">[</span>Step <span class="m">1</span><span class="o">]</span>: loading Harbor images ...
ba58b7bb3f17: Loading layer  <span class="m">33</span>.32MB/33.32MB
......略过......
Loaded image: goharbor/clair-photon:v2.0.8-v1.8.1


<span class="o">[</span>Step <span class="m">2</span><span class="o">]</span>: preparing environment ...
prepare base dir is <span class="nb">set</span> to /opt/harbor
Generated configuration file: /config/log/logrotate.conf
......略过......
Generated certificate, key file: /secret/core/private_key.pem, cert file: /secreCreating harbor-log ... <span class="k">done</span>
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir

Creating registry ... <span class="k">done</span>
Creating harbor-core ... <span class="k">done</span>
<span class="o">[</span>Step <span class="m">3</span><span class="o">]</span>: starting Harbor ...
Creating harbor-portal ... <span class="k">done</span>
Creating nginx ... <span class="k">done</span>
Creating harbor-db ... 
Creating redis ... 
Creating registryctl ... 
Creating registry ... 
Creating harbor-core ... 
Creating harbor-portal ... 
Creating harbor-jobservice ... 
Creating nginx ... 

✔ ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at http://HarborStudy. 
For more details, please visit https://github.com/goharbor/harbor .

$ 
</code></pre></div>

<p>安装成功，可以看看监听的端口，安装了哪些镜像，启动了哪些容器：</p>
<div class="highlight"><pre><span></span><code>$ ss -tnl
$ docker images
$ docker ps
</code></pre></div>

<h4 id="deng-lu-harbor"><a class="toclink" href="#deng-lu-harbor">登录 Harbor</a></h4>
<p>默认的密码在harbor.yml有设置的：</p>
<div class="highlight"><pre><span></span><code>harbor_admin_password: Harbor12345
</code></pre></div>

<p>用户名是admin，密码没改的话就是默认的，可以登录进去。  </p>
<p>使用浏览器访问Web页面，可以看到一些管理界面。<br>
另外要上传或下载镜像，需要在命令行使用docker命令，在那之前也需要登录Harbor，使用docker login命令来完成登录：</p>
<div class="highlight"><pre><span></span><code>$ docker login localhost
Username: admin
Password: 
WARNING! Your password will be stored unencrypted <span class="k">in</span> /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
$ 
</code></pre></div>

<p>登录成功之后，才能推送镜像。  </p>
<h4 id="ting-zhi-harbor"><a class="toclink" href="#ting-zhi-harbor">停止 Harbor</a></h4>
<p>要想停止或启动harbor，需要通过docker-compose命令。<br>
在操作之前，最好先切换目录到要操作的docker-compose.yml所在的目录，这样docker-compose能够自动找到模板文件并进行操作。<br>
停止harbor：</p>
<div class="highlight"><pre><span></span><code>$ <span class="nb">cd</span> /opt/harbor/
$ docker-compose stop
Stopping nginx             ... <span class="k">done</span>
Stopping harbor-portal     ... <span class="k">done</span>
Stopping harbor-jobservice ... <span class="k">done</span>
Stopping harbor-core       ... <span class="k">done</span>
Stopping registryctl       ... <span class="k">done</span>
Stopping harbor-db         ... <span class="k">done</span>
Stopping registry          ... <span class="k">done</span>
Stopping redis             ... <span class="k">done</span>
Stopping harbor-log        ... <span class="k">done</span>
$ 
</code></pre></div>

<p>然后再次启动：</p>
<div class="highlight"><pre><span></span><code>$ docker-compose start
Starting log         ... <span class="k">done</span>
Starting registry    ... <span class="k">done</span>
Starting registryctl ... <span class="k">done</span>
Starting postgresql  ... <span class="k">done</span>
Starting core        ... <span class="k">done</span>
Starting portal      ... <span class="k">done</span>
Starting redis       ... <span class="k">done</span>
Starting jobservice  ... <span class="k">done</span>
Starting proxy       ... <span class="k">done</span>
$ 
</code></pre></div>
      </div>
      <div class="back-to-top">
        <a href="/">HOME</a>
        <a href="#top">TOP</a>
      </div>
    </article>
  </div>
<!-- end article -->
<!-- 页面往下滚动一段之后才会显示TOC -->
<script>
  window.onscroll = function() {
    var tocbox = document.getElementsByClassName('toc')[0];
    var osTop = document.documentElement.scrollTop || document.body.scrollTop;
    var osWidth = document.documentElement.scrollWidth || document.body.scrollWidth;
    // console.log(osTop)
    if (osTop>300 && osWidth>865) {
      tocbox.style.display = "block"
    }
    if (osTop<300 || osWidth<865) {
      tocbox.style.display = "none"
    }
  }
</script>
                <footer>
                    <div class="icons">
                    </div>
                    <span id="busuanzi_container_page_pv" style="padding: 10px">本文阅读量<span id="busuanzi_value_page_pv"></span>次</span>
                    <span id="busuanzi_container_site_pv" style="padding: 10px">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
                    <span id="busuanzi_container_site_uv" style="padding: 10px">本站总访客数<span id="busuanzi_value_site_uv"></span>人</span>
                    <p>© <script>document.write(moment().format('YYYY'));</script> 749B</p>
                </footer>
        </div>
</body>
</html>